The problem can be found at the following link: Question Link
- Start from the root node.
- Traverse towards the left child of the current node until a leaf node is reached (the node with no left child).
- Return the value of the leaf node, which represents the minimum value in the binary search tree.
- Time Complexity:
O(H)
, whereH
is the height of the binary search tree. - Auxiliary Space Complexity:
O(1)
, since the space used is independent of the input size.
class Solution {
public:
int minValue(Node* root)
{
if (!root)
return -1;
if (root->left)
{
root=root->left;
minValue(root);
}
else return root->data;
}
};
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the getlost01/gfg-potd repository.